#include "system_init.h"
#include "Canfd.h"
/*******************************************************************************
**                     		   Global Functions 		             	      **
*******************************************************************************/
/**
 *  @brief :
 *  @param in :None
 *  @param out :None
 *  @retval :None
 */

void Canfd_Gpio_Init(void)
{
	//PB3=CANFD6TX,PB4=CANFD6RX

	GPIO_Reset (GPIOB_SFR);
	GPIO_Pull_Up_Enable(GPIOB_SFR, GPIO_PIN_MASK_3 | GPIO_PIN_MASK_4, TRUE);
	GPIO_Write_Mode_Bits(GPIOB_SFR, GPIO_PIN_MASK_3 | GPIO_PIN_MASK_4, GPIO_MODE_RMP);

	GPIO_Pin_RMP_Config(GPIOB_SFR, GPIO_Pin_Num_3, GPIO_RMP_AF6);
	GPIO_Pin_RMP_Config(GPIOB_SFR, GPIO_Pin_Num_4, GPIO_RMP_AF6);
}


Can_HwFilterType Can_HwFilter = {
		0x00000000U, /* Mask code */

		/* Fliter 1 */

		0x00000000U, /* Mask code */

		/* Fliter 2 */

		0x00000000U, /* Mask code */

		/* Fliter 3 */

		0x00000000U, /* Mask code */

		/* Fliter 4 */

		0x00000000U, /* Mask code */

		/* Fliter 5 */

		0x00000000U, /* Mask code */

		/* Fliter 6 */

		0x00000000U, /* Mask code */

		/* Fliter 7 */

		0x00000000U, /* Mask code */

		/* Fliter 8 */

		0x00000000U, /* Mask code */

		/* Fliter 9 */

		0x00000000U, /* Mask code */

		/* Fliter 10 */

		0x00000000U, /* Mask code */

		/* Fliter 11 */

		0x00000000U, /* Mask code */

		/* Fliter 12 */

		0x00000000U, /* Mask code */

		/* Fliter 13 */

		0x00000000U, /* Mask code */

		/* Fliter 14 */

		0x00000000U, /* Mask code */

		/* Fliter 15 */

		0x00000000U, /* Mask code */

		/* Fliter 16 */

		0x00000000U, /* Mask code */

		/* Fliter 17 */

		0x00000000U, /* Mask code */

		/* Fliter 18 */

		0x00000000U, /* Mask code */

		/* Fliter 19 */

		0x00000000U, /* Mask code */

		/* Fliter 20 */

		0x00000000U, /* Mask code */

		/* Fliter 21 */

		0x00000000U, /* Mask code */

		/* Fliter 22 */

		0x00000000U, /* Mask code */

		/* Fliter 23 */

		0x00000000U, /* Mask code */

		/* Fliter 24 */

		0x00000000U, /* Mask code */

		/* Fliter 25 */

		0x00000000U, /* Mask code */

		/* Fliter 26 */

		0x00000000U, /* Mask code */

		/* Fliter 27 */

		0x00000000U, /* Mask code */

		/* Fliter 28 */

		0x00000000U, /* Mask code */

		/* Fliter 29 */

		0x00000000U, /* Mask code */

		/* Fliter 30 */

		0x00000000U, /* Mask code */

		/* Fliter 31 */

		0x00000000U, /* Mask code */

		/* Fliter 32 */

		0x00000000U, /* Mask code */

		/* Fliter 33 */

		0x00000000U, /* Mask code */

		/* Fliter 34 */

		0x00000000U, /* Mask code */

		/* Fliter 35 */

		0x00000000U, /* Mask code */

		/* Fliter 36 */

		0x00000000U, /* Mask code */

		/* Fliter 37 */

		0x00000000U, /* Mask code */

		/* Fliter 38 */

		0x00000000U, /* Mask code */

		/* Fliter 39 */

		0x00000000U, /* Mask code */

		/* Fliter 40 */

		0x00000000U, /* Mask code */

		/* Fliter 41 */

		0x00000000U, /* Mask code */

		/* Fliter 42 */

		0x00000000U, /* Mask code */

		/* Fliter 43 */

		0x00000000U, /* Mask code */

		/* Fliter 44 */

		0x00000000U, /* Mask code */

		/* Fliter 45 */

		0x00000000U, /* Mask code */

		/* Fliter 46 */

		0x00000000U, /* Mask code */

		/* Fliter 47 */

		0x00000000U, /* Mask code */

		/* Fliter 48 */

		0x00000000U, /* Mask code */

		/* Fliter 49 */

		0x00000000U, /* Mask code */

		/* Fliter 50 */

		0x00000000U, /* Mask code */
	};


Can_Controller_BDRConfigType Canfd_Controller_AllClockAndBDRConfig[1] = {
	/* Default 1M hz */
	/* Clock and bandrate config 0 : Index 0 */
	{
		11U,				/* Prescale */
		1U,				/* Swj */
		14U,			/* Tseg1 */
		3U,				/* Tseg2 */
		CAN_SAMPLE_ONCE /* Sample time */
	},
};


Can_FdBDRConfigType Canfd_Controller_ALLFdBDRConfig[1] = {
	/* config 0 */
	{
		2U,	 /* Prescale */
		14U, /* Tseg1 */
		3U,	 /* Tseg2 */
	},
};



Can_ControllerConfigType Canfd_Controller_AllConfig[1] = {
	/* Can 0 Config */
	{
/* Can controller clock source set
            Value Range :
                CAN_CLOCKSOURCE_SCLK
                CAN_CLOCKSOURCE_HFCLK
                CAN_CLOCKSOURCE_LFCLK */
		CAN_CLOCKSOURCE_SCLK,

		/* Clock and bandrate config index(array index)
           refer to micro function define : Can_Controller_AllClockAndBDRConfig */
		0,

		CAN_CLOCKSOURCE_SCLK,

		/* CANFD mode bandrate config index(array index) */
		0,
		/* Mailbox block size config
             Value Range :
                CAN_8_BYTE_DATALENGTH :
                CAN_16_BYTE_DATALENGTH :
                CAN_32_BYTE_DATALENGTH :
                CAN_64_BYTE_DATALENGTH : */
		CAN_8_BYTE_DATALENGTH,
		/* Iso mode or non-iso mode config
            Value Range :
                CAN_FD_NON_ISOMODE :
                CAN_FD_ISOMODE : */
		CAN_FD_NON_ISOMODE,

		/* Global Mask Set */
		0xFFFFFFFF,
		/* Enable/disable mailbox full receive config
       Value Range :
            CAN_MBFULLRECEIVE_DISABLE
            CAN_MBFULLRECEIVE_ENABLE */
		CAN_MBFULLRECEIVE_DISABLE,

		/* Interrupt config : enable or disable interrupt */
		/* [$Block Start$] */
		{
			/* Rx interrupt set : Binding to CAN_0_RX_PROCESSING in Can_Cfg.h */

			CAN_INTERRUPT_ENABLE, /* Rx interrupt enable */

			/* Tx interrupt set : Binding to CAN_0_TX_PROCESSING in Can_Cfg.h */

			CAN_INTERRUPT_DISABLE, /* Tx interrupt enable */

			/* Busoff interrupt set : Binding to CAN_0_TX_PROCESSING in Can_Cfg.h */

			CAN_INTERRUPT_DISABLE, /* Busoff interrupt enable */

			CAN_INTERRUPT_DISABLE, /* Wakeup interrupt enable */

			/* Error alarm interrupt set */
			CAN_INTERRUPT_DISABLE,

			/* Rx data Overflow interrupt set */
			CAN_INTERRUPT_ENABLE, /* Rx data Overflow interrupt enable/disable */

			/* Negative error interupt set */
			CAN_INTERRUPT_DISABLE, /* Negative error interupt enable/disable */

			/* Arbitrate lose interupt set */
			CAN_INTERRUPT_DISABLE, /* Arbitrate lose interupt enable/disable */

			/* Bus error interupt set */
			CAN_INTERRUPT_DISABLE,

			CAN_INTERRUPT_DISABLE,
			CAN_INTERRUPT_DISABLE,
			CAN_INTERRUPT_DISABLE,
			CAN_INTERRUPT_DISABLE,
			CAN_INTERRUPT_DISABLE,
			CAN_INTERRUPT_DISABLE,
			CAN_INTERRUPT_DISABLE,
		},
		&Can_HwFilter,
		&Canfd_Controller_AllClockAndBDRConfig[0],
		&Canfd_Controller_ALLFdBDRConfig[0],
	},
	/* end */
};


Canfd_Sdu_Type Canfd_Sdu =
{
	{
		{
			{
				{
				 0x00,
				 0x01,
				 0x02,
				 0x03,
				 0x04,
				 0x05,
				 0x06,
				 0x07,
				 0x08,
				 0x09,
				 0x0A,
				 0x0B,
				 0x0C,
				 0x0D,
				 0x0E,
				 0x0F,
				 0x10,
				 0x11,
				 0x12,
				 0x13,
				 0x14,
				 0x15,
				 0x16,
				 0x17,
				 0x18,
				 0x19,
				 0x1A,
				 0x1B,
				 0x1C,
				 0x1D,
				 0x1E,
				 0x1F,
				 0x20,
				 0x21,
				 0x22,
				 0x23,
				 0x24,
				 0x25,
				 0x26,
				 0x27,
				 0x28,
				 0x29,
				 0x2A,
				 0x2B,
				 0x2C,
				 0x2D,
				 0x2E,
				 0x2F,
				 0x30,
				 0x31,
				 0x32,
				 0x33,
				 0x34,
				 0x35,
				 0x36,
				 0x37,
				 0x38,
				 0x39,
				 0x3A,
				 0x3B,
				 0x3C,
				 0x3D,
				 0x3E,
				 0x3F,
			 },
			 Data_Length_32},
			0x100,
			0x000,
			CANFD_BRS_DISABLE,

			CAN_FRAME_FD,
			CAN_ID_STANDARD,

			MAIL_TRANSMIT,
		},
	},
	1,
};
